package com.example.lab06;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.SeekBar;

public class MainActivity extends Activity {

	EditText editText;
	SeekBar seekBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		seekBar = (SeekBar) findViewById(R.id.seekBar1);
		editText = (EditText) findViewById(R.id.txtTextIO);
		seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				editText.setTextSize(progress);

			}
		});
		SharedPreferences sharedPreferences = getSharedPreferences(
				"SateOfMainActivity", MODE_PRIVATE);
		editText.setTextSize(sharedPreferences.getInt("FontSize", 14));
		seekBar.setProgress(sharedPreferences.getInt("FontSize", 14));
		editText.setText(sharedPreferences.getString("Content", "Test"));
	}

	public void onSave(View v) {
		// c1
		// SharedPreferences sharedPreferences=getPreferences(MODE_PRIVATE);
		// c2
		SharedPreferences sharedPreferences = getSharedPreferences(
				"SateOfMainActivity", MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("Content", editText.getText().toString());
		editor.putInt("FontSize", seekBar.getProgress());
		editor.apply();
	}

	public void onClick(View v) {
		Intent i = new Intent(getBaseContext(), IODemo.class);
		startActivity(i);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
